using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UserSorce.Entity.Models;

namespace UserLogicCore.Logic
{
   public class TypeService
    {
        private ToDoListWebContext _ctx = new ToDoListWebContext();
        /// <summary>
        /// 添加清单的类型
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="typeName"></param>
        public void AddType(int userId,string typeName)
        {
            UserSorce.Entity.Models.Type type = new UserSorce.Entity.Models.Type() {
            UserId = userId,
            TypeName= typeName
            };
            _ctx.Type.Add(type);
            _ctx.SaveChanges();
        }
        /// <summary>
        /// 删除清单的类型
        /// </summary>
        /// <param name="typeId"></param>
        public void DeleteType(int typeId)
        {
            UserSorce.Entity.Models.Type type = _ctx.Type.SingleOrDefault(prop => prop.TypeId == typeId);
            _ctx.Type.Remove(type);
            _ctx.SaveChanges();
        }
        /// <summary>
        /// 修改清单名称
        /// </summary>
        /// <param name="typeId"></param>
        /// <param name="typeName"></param>
        public void ChangeTypeName(int typeId,string typeName)
        {
            UserSorce.Entity.Models.Type type = _ctx.Type.SingleOrDefault(prop => prop.TypeId == typeId);
            type.TypeName = typeName;
            _ctx.SaveChanges();
        }
    }
}
